#include <mqueue.h>
#include <errno.h>
#include <sys/neutrino.h>

#define MAXMSG 1024	

int main()
{	mqd_t id;
	char mes[MAXMSG]="";
	unsigned int prior=1;
   	struct mq_attr sta;
	int mida,i,error;

	id=mq_open("cua",O_RDONLY,S_IRUSR|S_IWUSR,NULL);

    	printf("id %i errno %i \n",id,errno);
    	switch (errno)
	{   	case EACCES: printf("eacces\n"); break;
        	case EEXIST: printf("eexist\n"); break;
        	case EINTR: printf("eintr\n"); break;
        	case EINVAL: printf("einval\n"); break;
        	case ELOOP: printf("eloop\n"); break;
        	case EMFILE: printf("emfile\n"); break;
        	case ENAMETOOLONG: printf("enametoolong\n"); break;
        	case ENOENT: printf("enoent\n"); break;
        	case ENOSPC: printf("enospc\n"); break;
        	case ENOSYS: printf("enosys\n"); break;
    	}

    	error=mq_getattr(id,&sta);

	printf("llegeixo\n");

	mida=mq_receive(id,mes,sta.mq_msgsize,&prior);
    	printf("mq_receive: mida %i errno %i prioritat %d\n",mida,errno,prior);
    	switch (errno)
	{   	case EAGAIN: printf("eagain\n"); break;
        	case EBADF: printf("ebadf\n"); break;
        	case EINTR: printf("eintr\n"); break;
        	case EINVAL: printf("einval\n"); break;
       	 	case EMSGSIZE: printf("emsgsize\n"); break;
    	}
	printf("missatge: %s mida=%i prior= %i\n",mes,mida,prior);

	printf("acabo\n");

	mq_close(id);
}
